package linc.cool.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author yqlin
 * @date 2022/3/3 5:07 上午
 * @description
 */
@Slf4j
public class RabbitUtils {
    private static final ConnectionFactory factory = new ConnectionFactory();

    static {
        factory.setHost("127.0.0.1");
        factory.setPort(5672);
        factory.setVirtualHost("/admin");
        factory.setUsername("admin");
        factory.setPassword("admin");
    }

    public static Connection getConnection() {
        try {
            return factory.newConnection();
        } catch (IOException | TimeoutException e) {
            log.error("mq connection exception: {}", e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }
}
